#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* myshell.c */
void parent(int *status) {
    wait(status);
}

void split(char **arr, char *str, const char *del) {
    char *s = NULL;
    s = strtok(str, del);
    while (s != NULL) {
        *arr++ = s;
        s = strtok(NULL, del);
    }
}

void main() {
    char *args[10];
    char arg[100];
    pid_t pid;
    int status;

    while (1) {
        printf("please input command:\n");
        memset(args, 0x0, sizeof(args));
        gets(arg);
        if (strcmp("#", arg) == 0) break;
        split(args, arg, " ");
        pid = fork();
        if (pid < 0) {
            printf("fork failed\n");
            exit(0);
        } else if (pid == 0) {
            if (execvp(args[0], args + 1) == -1)
                printf("exec error!");
            printf("}");
        } else {
            wait(&status);
        }
    }
}
